package niconama04.model.impl;

import java.util.ArrayList;
import java.util.List;

import niconama04.model.Loader;
import niconama04.shared.data.Category;
import niconama04.shared.data.CategoryOriginal;
import niconama04.shared.data.Constants.Pos;
import niconama04.shared.data.Grammer;
import niconama04.shared.data.GrammerWord;
import niconama04.shared.data.Original;
import niconama04.shared.data.User;
import niconama04.shared.data.Word;


class LoaderImpl implements Loader {

	private final Dao dao;

	LoaderImpl(Dao x_dao) {
		dao = x_dao;
	}

	@Override
	public Grammer getGrammer(Long x_key) {
		return dao.getGrammer(x_key);
	}

	@Override
	public List<Grammer> getGrammers() {
		return dao.getGrammers();
	}

	@Override
	public Word getWord(Long x_key) {
		return dao.getWord(x_key);
	}

	@Override
	public List<Word> getWords() {
		return dao.getWords();
	}
	
	@Override
	public List<GrammerWord> getGrammerWords() {
		return dao.getGrammerWords();
	}

	@Override
	public Original getOriginal(Long x_key) {
		return dao.getOriginal(x_key);
	}

	@Override
	public List<Original> getOriginals() {
		return dao.getOriginals();
	}

	@Override
	public List<Original> getOriginals(Pos x_pos) {
		return dao.getOriginals(x_pos);
	}

	@Override
	public List<Original> getOriginals(Long x_categoryKey) {
		List<Original> result = new ArrayList<Original>();
		List<CategoryOriginal> cos = dao.getCategoryOriginals(x_categoryKey, null);
		for (CategoryOriginal co : cos) {
			Original o = dao.getOriginal(co.getOriginalKey());
			if (o != null) {
				result.add(o);
			}
		}
		return result;
	}

	@Override
	public Category getCategory(Long x_key) {
		return dao.getCategory(x_key);
	}
	
	@Override
	public List<Category> getCategorys() {
		return dao.getCategorys();
	}

	@Override
	public List<Category> getCategorys(Long x_originalKey) {
		List<Category> result = new ArrayList<Category>();
		List<CategoryOriginal> cos = dao.getCategoryOriginals(null, x_originalKey);
		for (CategoryOriginal co : cos) {
			Category c = dao.getCategory(co.getCategoryKey());
			if (c != null) {
				result.add(c);
			}
		}
		return result;
	}

	@Override
	public List<CategoryOriginal> getCategoryOriginals() {
		return dao.getCategoryOriginals();
	}

	@Override
	public User getUser(Long x_key) {
		return dao.getUser(x_key);
	}
}
